<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人和人律师事务所管理系统v1.0-现金帐管理</title>

<style type="text/css" media="all">
.allow-float {
	clear: none !important;
}  /* 允许该元素浮动 */
.stop-float {
	clear: both !important;
}  /* 阻止该元素浮动 */
.float-left {
	float: left;
	padding-left: 10px
} /*浮动到左边*/
</style>

<script type="text/javascript">
Ext.onReady(function(){
		//添加现金帐信息窗口
		var addCashWindow;
		//添加现金帐信息form
		var addCashForm;

		//查看报表窗口
		var reportFormCWindow;
		//查看报表信息面板
		var reportFormCPanel;

		//选择要查的具体时间下拉框
		var formCDetaisCombo;




		var formCatalog=[{catalogId:1,catalogName:'年报表'},{catalogId:2,catalogName:'季报表'},{catalogId:3,catalogName:'月报表'}];

var formDetails=new Array();
//年报表
formDetails[1]=[{detailValue:'2003',detailName:'2003'},{detailValue:'2004',detailName:'2004'},{detailValue:'2005',detailName:'2005'},
{detailValue:'2006',detailName:'2006'},{detailValue:'2007',detailName:'2007'},{detailValue:'2008',detailName:'2008'},{detailValue:'2009',detailName:'2009'},{detailValue:'2010',detailName:'2010'},{detailValue:'2011',detailName:'2011'},
{detailValue:'2012',detailName:'2012'},{detailValue:'2013',detailName:'2013'},{detailValue:'2014',detailName:'2014'},{detailValue:'2015',detailName:'2015'},
{detailValue:'2016',detailName:'2016'},{detailValue:'2017',detailName:'2017'},{detailValue:'2018',detailName:'2018'},{detailValue:'2019',detailName:'2019'},{detailValue:'2020',detailName:'2020'}];
//季报表
formDetails[2]=[{detailValue:'01',detailName:'第一季度'},{detailValue:'02',detailName:'第二季度'},
{detailValue:'03',detailName:'第三季度'},{detailValue:'04',detailName:'第四季度'}];
//月报表
formDetails[3]=[{detailValue:'01',detailName:'一月份'},{detailValue:'02',detailName:'二月份'},{detailValue:'03',detailName:'三月份'},
{detailValue:'04',detailName:'四月份'},{detailValue:'05',detailName:'五月份'},{detailValue:'06',detailName:'六月份'},
{detailValue:'07',detailName:'七月份'},{detailValue:'08',detailName:'八月份'},{detailValue:'09',detailName:'九月份'},
{detailValue:'10',detailName:'十月份'},{detailValue:'11',detailName:'十一月份'},{detailValue:'12',detailName:'十二月份'}];

// 报表种类store
var catalogStore=new Ext.data.JsonStore({
data:formCatalog,
fields:["catalogId","catalogName"]
});
//具体时间Store
var detailStore=new Ext.data.JsonStore({
			data:[],
			fields:["detailValue","detailName"]
			});

	//月份JSON型数据
		var datas=[{id:'01',
		name:'一月份'},
		{id:'02',
		name:'二月份'},
		{id:'03',
		name:'三月份'},
		{id:'04',
		name:'四月份'},
		{id:'05',
		name:'五月份'},
		{id:'06',
		name:'六月份'},
		{id:'07',
		name:'七月份'},
		{id:'08',
		name:'八月份'},
		{id:'09',
		name:'九月份'},
		{id:'10',
		name:'十月份'},
		{id:'11',
		name:'十一月份'},
		{id:'12',
		name:'十二月份'}
		];
//月份STORE
var monthstore=new Ext.data.JsonStore({ data:datas,fields:["id","name"]});
//查询框
    var seacashWinPanel = new Ext.form.FormPanel({
   		    labelAlign:'right',
			title:'现金账查询',
			labelSeparator :'：',//分隔符
			labelWidth : 80,//标签宽度
			bodyStyle:'padding:5',//表单边距
			frame : true,
			collapsible: true,
			height:100,
			width:window.screen.width-220,
			applyTo :'searchCashWin',

			items:[
				new Ext.form.TextField({
					fieldLabel : '请输入年份',
					id : 'cashYear',
					name : 'cashYear',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.form.ComboBox({
					fieldLabel:'请选择月份',
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					store:monthstore,
					valueField:'id',
					displayField:'name',
					mode:'local',
					forceSelection:true,
					emptyText:'请选择月份',
					editable:false,
					triggerAction:'all',
					id:'cashMonth',
					name:'cashMonth'
				}),

				new Ext.Button({
					text : '开始查询',
					iconCls:'search',
					cls:'float-left',//向左浮动
					handler : submitMsg
				})
			]

		})



		//查询处理函数
	function submitMsg(){
		//获得要查询的年份与月份
		var cashYear=Ext.getCmp("cashYear").getValue();
		//判断是否输入了年份
		if(cashYear==null||cashYear=="")
		{
		Ext.Msg.alert('信息', '请输入年份再提交!');
		return;
		}
		var cashMonth=Ext.getCmp("cashMonth").getValue();

		 store = new Ext.data.JsonStore({
	url:"SearchCashInfo.jsj?cashYear="+cashYear+"&cashMonth="+cashMonth,
	totalProperty: 'totalCount',
    root: 'result',
	fields:["cashaccid","cashacctime","cashaccbrief","incomemoney","payoutmoney"]
});
		store.reload({
			params:{
				start:0,
				limit:5
				}
			});
		var colModel = new Ext.grid.ColumnModel([//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "计入时间",width: 200,  dataIndex: 'cashacctime', sortable: true},
				{header: "收入金额", width: 200,dataIndex: 'incomemoney', sortable: true},
				{header: "支出金额",width: 200, dataIndex: 'payoutmoney', sortable: true},
				{header: "摘要",width: 300, dataIndex: 'cashaccbrief', sortable: true},
				]);
				pagebar.bind(store);
				grid.reconfigure(store,colModel);
		grid.getView().refresh(true);
	}

    //存储器
		var store = new Ext.data.JsonStore({
	url:"CashInfoRequest.jsj",
	totalProperty: 'totalCount',
	root: 'result',
	fields:["cashaccid","cashacctime","cashaccbrief","incomemoney","payoutmoney"]
	});
		store.load({
			params:{
				start:0,
				limit:5
				}
			});

	//获得用户权限
		var buttonDisabled=true;
	<%
	if((java.lang.Integer)session.getAttribute("popedomLevel")==1){
		%>
		buttonDisabled=false;
	<%
	}
	%>



	//创建工具栏组件
		var toolbar = new Ext.Toolbar([
			{text : '现金帐详细信息'},
			'-',
			{
			text:'报表查看',
			iconCls:'search',
			handler:function(btn,pressed){
			lookCashRecordForm();
			}
			},
			'-',
			{
			text:'查看资金余额',
			iconCls:'search',
			handler:function(btn,pressed){
			cashLeftMoneyFun();
			}
			},
			'-',
			{
			text:'时间段资金查看',
			iconCls:'search',
			handler:function(btn,pressed){
			someTimeMoneyFun();
			}
			},
			'-',
			{
			text:'增加现金帐信息',
			iconCls:'add',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			addCashInfo();
			}
			},
			'-',
			{
			text:'修改',
			iconCls:'option',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			modifyCashFun();
			}
			}
		]);




     //修改现金帐面板
     var modifyCashPanel;
     //修改现金帐窗口
      var modifyCashWin;
      //修改现金帐记录
       function modifyCashFun(){
		//获取要修改的一条记录
       	var record=grid.getSelectionModel().getSelected();
       	//如果用户没有选择
       	if(!record){
       		Ext.MessageBox.alert('修改操作','请选择要修改的一项！');
       	}else{
       		//修改现金帐窗口
       		modifyCashWin=new Ext.Window({
       			labelAlign:'right',
       			layout:'fit',
       			width:400,
       			height:300,
       			closeAction:'hide',
				plain:true,
				title:'修改现金帐窗口',
				items:modifyCashPanel
       		});
       		modifyCashWin.show();
       		 Ext.getCmp("mcashId").setValue(record.get("cashaccid"));
       		  Ext.getCmp("mcashTime").setValue(record.get("cashacctime"));
       		   Ext.getCmp("mcashIncome").setValue(record.get("incomemoney"));
       		    Ext.getCmp("mcashPayout").setValue(record.get("payoutmoney"));
       		     Ext.getCmp("mcashBrief").setValue(record.get("cashaccbrief"));


       	}
       }

       //修改现金帐面板
       modifyCashPanel=new Ext.form.FormPanel({
       	collapsible:true,
       	labelwidth:100,
       	buttonAlign:'center',
       	frame:true,
       	bodyStyle : 'padding:5px 5px 0',
        waitMsgTarget : true,
        defaultType : 'textfield',
        items : [
         {
         	xtype:'hidden',
            name :'mcashId',
             id :'mcashId'
        },
        {
            fieldLabel : '计入时间',
            itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
            name :'mcashTime',
             id :'mcashTime',
            allowBlank :false
        },
        {
            fieldLabel : '收入金额',
            itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
            name :'mcashIncome',
             id :'mcashIncome',
            allowBlank :false
        },
        {
                   fieldLabel :'支出金额',
					id :'mcashPayout',
					name :'mcashPayout',
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					allowBlank :false
        },
          {
                   fieldLabel :'摘要',
					id :'mcashBrief',
					name :'mcashBrief',
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					allowBlank :false
        }
        ],

               buttons : [ {
            text : '修改',
            disabled : false,
            handler : function() {
                if (modifyCashPanel.form.isValid()) {
                    modifyCashPanel.form.submit( {
                        url : 'ModifyCashInfo.jsj',
                        success : function(from, action) {
                         Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyCashWin.hide();
                        },
                        failure : function(form, action) {
                           Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyCashWin.hide();
                        },
                        waitMsg : '正在保存数据，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        }, {
            text : '取消',
            handler : function() {
                modifyCashWin.hide();
            }
        }]
       })

			//查看现金总资金form
			var cashLeftMoneyForm;
			//查看现金总资金窗口
			var cashLeftMoneyWindow;
			//查看现金帐总资金
			function cashLeftMoneyFun(){
       cashLeftMoneyWindow=new Ext.Window({
			title:'现金帐总资金查看窗口',
			width:280,
			height:120,
			layout:'fit',
			closeAction:'hide',
			resizable:false,
			items:cashLeftMoneyForm
		});
		cashLeftMoneyWindow.show();
		//发送请求加载数据
		cashLeftMoneyForm.getForm().load({
        url:'LookcashLeftMoney.jsj',
       waitMsg : '正在载入数据...'
        });
	}
	//查看现金帐总资金面板
	 cashLeftMoneyForm=new Ext.FormPanel({
	 		labelAlign:'right',
	 		buttonAlign:'center',
	 		frame:true,
	 		labelWidth:100,
	 		defaults:{
	 		width:120,
	 		},
	 		reader: new Ext.data.JsonReader({root:'result'},
                                       [
                                       {name: 'cashleftmoney',mapping:'cashleftmoney',type:'int'}
                                      ]),
		items:[
		{
			xtype:'textfield',
			fieldLabel:'现金帐总资金',
			name:'cashleftmoney',
			allowBlank:false
		}
		],
		buttons:[{
		text:'确认',
		handler:function(){
			cashLeftMoneyWindow.hide();
		}
		}]
	});


		var someTimeMoneyWindow;
		var someTimeMoneyPanel;

	//查看时间段资金处理函数
		function someTimeMoneyFun(){
			someTimeMoneyWindow= new Ext.Window({
			title:'资金查看窗口',
			width:400,
			height:300,
			layout:'fit',
			closeAction:'hide',
			resizable:false,
			items:someTimeMoneyPanel
			})
		someTimeMoneyWindow.show();
		}

		//时间段资金查看面板
		someTimeMoneyPanel=new Ext.FormPanel({
			labelAlign:'right',
	 		frame:true,
	 		labelWidth:100,
	 		buttonAlign:'center',
	 		defaults:{
	 		width:200
	 		},
	 		items:[
	 		{
			xtype:'datefield',
			format:'Y-m-d',
			fieldLabel:'开始时间',
			id:'cashStartTime',
			name:'cashStartTime',
			allowBlank:false
		},
		{
			xtype:'datefield',
			format:'Y-m-d',
			fieldLabel:'结束时间',
			id:'cashEndTime',
			name:'cashEndTime',
			allowBlank:false
		},

				{
				height:50,
				},

				{
			xtype:'textfield',
			fieldLabel:'收入金额',
			id:'tcashIncome',
			name:'tcashIncome',
			allowBlank:true
		},
		{
			xtype:'textfield',
			fieldLabel:'支出金额',
			id:'tcashPayout',
			name:'tcashPayout',
			allowBlank:true
		},
		{
			xtype:'textfield',
			fieldLabel:'资金余额',
			id:'tcashFinanceLeave',
			name:'tcashFinanceLeave',
			allowBlank:true
		}],
		 buttons : [ {
            text : '确认',
            disabled : false,
            handler : function() {
                if (someTimeMoneyPanel.form.isValid()) {
                    someTimeMoneyPanel.form.submit( {
                        url : 'TimeCashFinanceLook.jsj',
                        success : function(from, action) {
                         var result=action.result.message;
							var resultArr=result.split(",");
							Ext.getCmp("tcashIncome").setValue(resultArr[0]);
							Ext.getCmp("tcashPayout").setValue(resultArr[1]);
							Ext.getCmp("tcashFinanceLeave").setValue(resultArr[2]);
                        },
                        failure : function(form, action) {
                           var result=action.result.message;
							var resultArr=result.split(",");
							Ext.getCmp("tcashIncome").setValue(resultArr[0]);
							Ext.getCmp("tcashPayout").setValue(resultArr[1]);
							Ext.getCmp("tcashFinanceLeave").setValue(resultArr[2]);
                        },
                        waitMsg : '正在发送请求，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        },{
        text:'取消',
        handler: function(){
        someTimeMoneyWindow.hide();
        }
        }
        ]
		})


		//查看报表处理函数
		function lookCashRecordForm(){
			reportFormCWindow= new Ext.Window({
			title:'查看报表信息窗口',
			width:400,
			height:300,
			layout:'fit',
			closeAction:'hide',
			resizable:false,
			items:reportFormCPanel
			})
		reportFormCWindow.show();
		}

		//查看报表面板
		reportFormCPanel=new Ext.FormPanel({
			labelAlign:'right',
	 		frame:true,
	 		labelWidth:100,
	 		buttonAlign:'center',
	 		defaults:{
	 		width:200
	 		},
	 		items:[
	 		new Ext.form.ComboBox({
			fieldLabel:'请选择报表种类',
			store: catalogStore,
			valueField:'catalogId',
			displayField:'catalogName',
			mode:'local',
			hiddenName:'catalog',
			forceSelection:true,
			emptyText:'请选择报表种类',
			editable:false,
			triggerAction:'all',
			id:'cashCatalogId',
			listeners:{
			select:function(combo,record,index){
			Ext.getCmp("cashDetailTime").clearValue();
			Ext.getCmp("cashDetailTime").store.loadData(formDetails[record.data.catalogId]);
			}
			}
			}),

			new Ext.form.ComboBox({
					fieldLabel:'请选择具体时间',
					store:detailStore,
					valueField:'detailValue',
					displayField:'detailName',
					mode:'local',
					hiddenName:'time',
					forceSelection:true,
					emptyText:'请选择具体时间',
					editable:false,
					triggerAction:'all',
					id:'cashDetailTime'
				}),

				{
				height:50,
				},

				{
			xtype:'textfield',
			fieldLabel:'收入金额',
			id:'cashIncome',
			name:'cashIncome',
			allowBlank:true
		},
		{
			xtype:'textfield',
			fieldLabel:'支出金额',
			id:'cashPayout',
			name:'cashPayout',
			allowBlank:true
		},
		{
			xtype:'textfield',
			fieldLabel:'资金余额',
			id:'cashFinanceLeave',
			name:'cashFinanceLeave',
			allowBlank:true
		}],
		 buttons : [ {
            text : '确认',
            disabled : false,
            handler : function() {
                if (reportFormCPanel.form.isValid()) {
                    reportFormCPanel.form.submit( {
                        url : 'CashFinanceReportForm.jsj',
                        success : function(from, action) {
                         var result=action.result.message;
							var resultArr=result.split(",");
							Ext.getCmp("cashIncome").setValue(resultArr[0]);
							Ext.getCmp("cashPayout").setValue(resultArr[1]);
							Ext.getCmp("cashFinanceLeave").setValue(resultArr[2]);
                        },
                        failure : function(form, action) {
                           var result=action.result.message;
							var resultArr=result.split(",");
							Ext.getCmp("cashIncome").setValue(resultArr[0]);
							Ext.getCmp("cashPayout").setValue(resultArr[1]);
							Ext.getCmp("cashFinanceLeave").setValue(resultArr[2]);
                        },
                        waitMsg : '正在发送请求，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        },{
        text:'取消',
        handler: function(){
        reportFormCWindow.hide();
        }
        }
        ]
		})

//增加一条现金账信息处理函数
function addCashInfo(){
		 addCashWindow=new Ext.Window({
			title:'增加一条现金帐记录',
			width:550,
			height:260,
			layout:'fit',
			closeAction:'hide',
			resizable:false,
			items:addCashForm
		});
		addCashWindow.show();
	}
	//增加现金帐面板
	 addCashForm=new Ext.FormPanel({
	 		labelAlign:'right',
	 		frame:true,
	 		labelWidth:180,
	 		buttonAlign:'center',
	 		defaults:{
	 		width:180,
	 		},
		items:[
		{
			xtype:'datefield',
			fieldLabel:'时间',
			format:'Y-m-d',
			name:'cashAccTime',
			allowBlank:false
		},
		{
			xtype:'textfield',
			fieldLabel:'收入金额(非收入记录，填0)',
			name:'cashIncome',
			allowBlank:false
		},
		{
			xtype:'textfield',
			fieldLabel:'支出金额(非支出记录，填0)',
			name:'cashPayout',
			allowBlank:false
		},
		{
			xtype:'textarea',
			fieldLabel:'账目摘要',
			height:100,
			name:'cashBrief',
			allowBlank:false
		}
		],
		buttons:[{
		text:'确认',
		handler:function(){
			if(addCashForm.form.isValid()){
				addCashForm.form.submit({
				url:'AddCashAccount.jsj',
				success:function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addCashWindow.hide();
				},
				failure: function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addCashWindow.hide();
				},
				waitMsg:'正在保存数据，稍后...'
				});
			} else {
				Ext.Msg.alert('信息', '请填写完成再提交!');
			}
		}
		},{
		 text:'取消',
		 handler:function(){
		 	addCashWindow.hide();
		 }
		}]
	});

		//分页工具栏
		var pagebar = new Ext.PagingToolbar({
			store : store,
			pageSize : 5,
			displayInfo : true,
			displayMsg : '第 {0} ~ {1} 条 共 {2} 条',
			emptyMsg : '当前没有记录'
		});
		//创建选择模式对象
	var cb = new Ext.grid.CheckboxSelectionModel()
	//创建Grid表格组件
	var grid = new Ext.grid.GridPanel({
			renderTo : 'cash-detail-info',
			frame : true,
			tbar : toolbar,
			bbar : pagebar,
			trackMouseOver:true, //鼠标特效
			loadMask: true,    //是否显示正在加载
			store : store,
			height : 320,
			width : window.screen.width-220,
			stripeRows : true,
			autoScroll : true,
			viewConfig : {autoFill : true},
			sm : cb,
			columns: [//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "计入时间", width: 100, dataIndex: 'cashacctime', sortable: true},
				{header: "收入金额", width: 75, dataIndex: 'incomemoney', sortable: true},
				{header: "支出金额", width: 75, dataIndex: 'payoutmoney', sortable: true},
				{header: "摘要", width: 75, dataIndex: 'cashaccbrief', sortable: true},
				]
		});


});

</script>
</head>
<body>
<table>
	<tr>
		<td>
		<div id='searchCashWin' style="margin: 8px 8px 4px 8px"></div>
		</td>
	</tr>
</table>
<div id='cash-detail-info' style="margin: 4px 8px 8px 8px"></div>


</body>
</html>